<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="id">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="0: "等待", 1: "正在识别", 2: "识别结束", 3: "暂停"，4:"暂停中"，5：”“">
            <el-input v-model="form.taskName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="jsonPath">
            <el-input v-model="form.jsonPath" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="weight" prop="weight">
            <el-input v-model="form.weight" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="jsonCount">
            <el-input v-model="form.jsonCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="submitTime">
            <el-input v-model="form.submitTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="status">
            <el-input v-model="form.status" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="finishTime">
            <el-input v-model="form.finishTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="finishedCount">
            <el-input v-model="form.finishedCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="remainingCount">
            <el-input v-model="form.remainingCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="resultPath">
            <el-input v-model="form.resultPath" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="forceUpdate">
            <el-input v-model="form.forceUpdate" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="0不保存识别结果图片/1保存识别结果图片">
            <el-input v-model="form.saveResultImage" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="id" />
        <el-table-column prop="taskName" label="0: "等待", 1: "正在识别", 2: "识别结束", 3: "暂停"，4:"暂停中"，5：”“" />
        <el-table-column prop="jsonPath" label="jsonPath" />
        <el-table-column prop="weight" label="weight" />
        <el-table-column prop="jsonCount" label="jsonCount" />
        <el-table-column prop="submitTime" label="submitTime" />
        <el-table-column prop="status" label="status" />
        <el-table-column prop="finishTime" label="finishTime" />
        <el-table-column prop="finishedCount" label="finishedCount" />
        <el-table-column prop="remainingCount" label="remainingCount" />
        <el-table-column prop="resultPath" label="resultPath" />
        <el-table-column prop="forceUpdate" label="forceUpdate" />
        <el-table-column prop="saveResultImage" label="0不保存识别结果图片/1保存识别结果图片" />
        <el-table-column v-if="checkPer(['admin','task:edit','task:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudTask from '@/api/task'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, taskName: null, jsonPath: null, weight: null, jsonCount: null, submitTime: null, status: null, finishTime: null, finishedCount: null, remainingCount: null, resultPath: null, forceUpdate: null, saveResultImage: null }
export default {
  name: 'Task',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: 'Task', url: 'api/task', idField: 'id', sort: 'id,desc', crudMethod: { ...crudTask }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'task:add'],
        edit: ['admin', 'task:edit'],
        del: ['admin', 'task:del']
      },
      rules: {
        weight: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]
      }    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
